package com.gexiaobao.pigeon.ui.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.EditBloodInfoBean
import com.gexiaobao.pigeon.databinding.ItemFourV2StyleBinding
import com.gexiaobao.pigeon.databinding.ItemFourV3StyleBinding

/**
 * @Author      : hxw
 * @Date        : 2024/9/21 9:51
 * @Describe    :
 */
class AdapterFourV3Style(data: ArrayList<EditBloodInfoBean>) :
    BaseQuickAdapter<EditBloodInfoBean, DataBindBaseViewHolder>(R.layout.item_four_v3_style, data) {
    override fun convert(holder: DataBindBaseViewHolder, item: EditBloodInfoBean) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemFourV3StyleBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        val title = when (holder.layoutPosition) {
            0 -> context.getString(R.string.grandfather)
            1 -> context.getString(R.string.grandmother)
            2 -> context.getString(R.string.grandfather_w)//"外祖父"
            else -> context.getString(R.string.grandmother_w)//"外祖母"
        }
        holder.setText(R.id.tvItemTitleFourV, title)

        val sexIcon: Int
        val bg: Int
        if (holder.layoutPosition % 2 == 0) {//偶数
            sexIcon = R.mipmap.icon_male
            bg = R.drawable.round8_male_pigeon_linear_bg
        } else {
            sexIcon = R.mipmap.icon_female
            bg = R.drawable.round8_female_pigeon_linear_bg

        }
        holder.setImageResource(R.id.ivItemSex, sexIcon)
        holder.setBackgroundResource(R.id.tvItemRingId, bg)
    }

    // 更新单个 item 的方法
    fun updateItem(position: Int, dataBean: EditBloodInfoBean?) {
        if (position >= 0 && position < data.size) {
            val item: EditBloodInfoBean = data[position]
            if (dataBean != null) {
                item.country = dataBean.country
                item.countryEn = dataBean.countryEn
                item.featherColor = dataBean.featherColor
                item.ringId = dataBean.ringId
                item.name = dataBean.name
                item.sex = dataBean.sex
                item.eye = dataBean.eye
                item.gradesDesc = dataBean.gradesDesc
                item.title = dataBean.title
                item.level = dataBean.level
                item.levelInfo = dataBean.levelInfo
            }
            notifyItemChanged(position)
        }
    }
}